/*** 
 * @Author: pengcheng
 * @Date: 2021-06-24 10:27:50
 * @LastEditTime: 2021-06-24 16:04:30
 * @LastEditors: pengcheng
 * @Description: 
 * @FilePath: /kylin-daq/src/LogRecord.h
 */
#ifndef LOGRECORD_H
#define LOGRECORD_H

#include <QtCore/QtCore>
#include <iostream>

class LogRecord:public QObject
{
public:
private:
    // static constexpr const char *s_logBaseFolderPath = "/var/log/";
    static constexpr const char *s_logBaseFolderPath = "/.log/";
    static QScopedPointer<LogRecord> ms_instance;
    bool m_HandleQtMessages;
    QDate m_setDate;
    qint64 m_startTimeMsec;
    QString m_appName;
    QString m_logFilePath;
    QString m_logDirPath;
    QFile m_logFile;
    QMutex m_writeFileMutexLock;
public:
    static LogRecord *instance(void);
    static void init(const QString &strAppName);
    static void shutdown();
    ~LogRecord();
protected:
    explicit LogRecord(QObject *parent = nullptr);
private:
    static void qtMessageHandler(QtMsgType type,
                                 const QMessageLogContext &context,
                                 const QString &message);
    void record(const QString &message);
    void doInit(const QString &strAppName);
    void setDate();
};

#endif
